package com.qumap.edititem.update.callback;

import com.google.gwt.user.client.Window;
import com.qumap.item.event.ItemEvent;
import com.qumap.item.event.ItemEventCollection;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 28.05.11
 * Time: 10:17
 * To change this template use File | Settings | File Templates.
 */
public class SaveCallback extends ChangeCallback<Integer> {
    @Override
    public void onFailure(Throwable throwable) {
        Window.alert("Item save failure "+throwable);
    }

    @Override
    public void onSuccess(Integer integer) {
        update_item.getContent().setId(integer.intValue());
        update_item.setHashChanges(false);
        update_item.setFullyLoad();
        sendItemSaveNotification();
        sendSelectEvent(update_item);
    }

    private void sendItemSaveNotification() {
        ItemEvent update_event = ItemEventCollection.getCollection().getEvent(ItemEventCollection.EventType.Saved);
        update_event.add(update_item);
        sendItemEvent(update_event);
    }


}
